<style>
  .red {
    color: red;
  }
</style>
<div id="app"></div>
<script>
  function h(tag, props, children) {
    return {
      tag,
      props,
      children,
    };
  }

  function mount(vnode, container) {
    const el = document.createElement(vnode.tag);

    // props
    if (vnode.props) {
      for (const key in vnode.props) {
        const value = vnode.props[key];
        el.setAttribute(key, value);
      }
    }

    // children
    if (vnode.children) {
      if (typeof vnode.children === "string") {
        el.textContent = vnode.children;
      } else {
        vnode.children.forEach((child) => {
          mount(child, el);
        });
      }
    }
    container.appendChild(el);
  }

  function patch(n1, n2) {
    const el = (n2.el = n1.el);

    // n1 旧快照
    // n2 新快照
    if (n1.tag === n2.tag) {
      const oldProps = n1.props || {};
      const newProps = n2.props || {};

      // props 更新
      for (const key in newProps) {
        const oldValue = oldProps[key];
        const newValue = newProps[key];
        if (newValue !== oldValue) {
          el.setAttribute(key, newValue);
        }
      }

      // key删除
      for (const key in oldProps) {
        if (!(key in newProps)) {
          el.removeAttribute(key);
        }
      }

      // children
      const oldChidren = n1.children
      const newChildren 
    }
  }

  const vdom = h("div", { class: "red" }, [h("span", null, "hello")]);

  const vdom = h("div", { class: "green" }, [h("span", null, "changed!")]);

  mount(vdom, document.getElementById("app"));

  patch(vdom, vdom2);
</script>
